package model

import (
	"time"
)

// ShareLogs SignLogs用户
type ShareLogs struct {
	Id      int       `xorm:"INT(11) PK AUTOINCR comment('主键')" json:"id"` //主键
	SUid    int       `xorm:"INT(11)" json:"suid"`
	TUid    int       `xorm:"INT(11)" json:"tuid"`
	Created time.Time `xorm:"DATETIME INDEX" json:"created"`
	Updated time.Time `xorm:"DATETIME" json:"updated"`
}

func (ShareLogs) TableName() string {
	return "app_share_logs"
}

func ShareLogAdd(mod *ShareLogs) error {
	sess := db.NewSession()
	defer sess.Close()
	sess.Begin()
	if _, err := sess.Insert(mod); err != nil {
		sess.Rollback()
		return err
	}
	sess.Commit()
	return nil
}

func GetAllShareLogs(uid int, pageNum int, pageSize int) ([]ShareLogs, error) {
	mods := make([]ShareLogs, 0, 4)
	sess := db.NewSession()
	defer sess.Close()

	if uid > 0 {
		sess.Where("s_uid = ?", uid)
	}
	err := sess.Desc("id").Limit(pageSize*(pageNum), (pageNum-1)*pageSize).Find(&mods)
	return mods, err
}
